(function(){
	@@include("./common/_popWindow.js")
	@@include("./common/_infiniteScroll.js")
	var height = $('.menu').outerHeight();
	var proportion = $(window).width()/375;
	$(".current>.rank").removeClass("animation");
	var $menu = $(".menu");
	var length = $menu.find(".list li").length;
	$(".navbar-toggle").on("click",function(){
		if($menu.hasClass('collapsed')){
			$menu.removeClass('collapsed')
			$menu.find(".list").animate({"height":"0"});
			$("html").removeClass("fixation");

		}else{
			$menu.addClass('collapsed')
			$menu.find(".list").animate({"height":(45*length+75)*proportion+"px"});
			$("html").addClass("fixation");
		}
	})

	$(".attention").on("click",function(){
		var postData={id:"XXX",state:1,type:1},
		    that = $(this),
		    followFlag = 1;
		if($(this).hasClass('favorited')){
			postData.state = 2
			followFlag = 2
		}
		$.ajax({
		  type: 'POST',
		  url: "./lib/fllow.json",
		  data: postData,
		  dataType: 'json',
		  success: function(data){
		  	if(data.code == 200){
		  		if(followFlag == 1){
		  			that.addClass('favorited')
		  		}
		  		if(followFlag == 2){
		  			that.removeClass('favorited')
		  		}
		  	}
		  },
		});
	})

	$(".more").on("click",function(){
		if($(this).hasClass("down")){
			$(this).parent().addClass("div-ellipsis");
			$(this).removeClass("down").text("View More");
		} else {
			$(this).addClass("down").text("Roll Up");
			$(this).parent().removeClass("div-ellipsis");
		}
	})
	$(".view-more").on("click",function(){
		if($(this).hasClass("down")){
			$(this).parent().addClass("detail-ellipsis");
			$(this).removeClass("down").html("View More<i></i>");
		} else {
			$(this).addClass("down").html("Roll Up<i></i>");
			$(this).parent().removeClass("detail-ellipsis");
		}
	})
	$(".rank li").on("click",function(){
		if($("html").hasClass("fixation")) return;
		var index = $(this).index();
		var top  = $(".current .production-detail")[index].offsetTop - height;
		$("html,body").animate({scrollTop:top},Math.min(200*++index,500));
	})
	$('.attribute li').on("click",function(){
    	if($(this).hasClass('current')) return
    	$(this).addClass('current').siblings().removeClass('current');
    	$(".current .rank").addClass("animation");
    	var index = $('.attribute li').index($(this));
    	length = $(".current>.production-detail").length;
    	$('.production').eq(index).addClass('current').siblings(".production").removeClass('current');
    	setTimeout(function(){$(".current>.rank").removeClass("animation");},50);
    })
    function init(){
    	try{
    		if(window.location.hash && /#[0-9]+$/.test(window.location.hash)){
	    		var hash = /#(\d+)/.exec(window.location.hash)[1];
		    	if(hash && hash<=$('.current .rank li').length){
		    		$('.current .rank li').eq(hash-1).trigger("click");
		    	}
	    	}  
    	}catch(e){}    	  		
	}
	init();
})()